package bishi.day25_5_23;

import java.util.Scanner;

/**
 * @author 是阿秋啊
 * @date 2022/05/24 12:34
 **/
public class shu_gen {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.nextLine();
            while (s.length() > 1) {
                int num = 0;
                for (int i = 0; i < s.length(); i++) {
                    num+=s.charAt(i) - '0';
                }
                s= String.valueOf(num);
            }
            System.out.println(s);
        }
    }
}